#if !defined(AFX_DLGSUPPORT_H__BE7BBB1E_38A3_4B11_A990_73A4719CD3DA__INCLUDED_)
#define AFX_DLGSUPPORT_H__BE7BBB1E_38A3_4B11_A990_73A4719CD3DA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgSupport.h : header file
//
#include "PHSShareRes.h"
#include "supporthanger.h"
#include "ManagerTemplate.h"
#include "ModelParamVisitor.h"
/////////////////////////////////////////////////////////////////////////////
// CDlgSupport dialog

class ModelParamVisitorManager : public ManagerTemplate<INT, ModelParamVisitor>
{
public:
	ModelParamVisitorManager(){
	}
	virtual ~ModelParamVisitorManager(){}

public:
	ModelParamVisitor* GetVisitor(INT nKey){
		ModelParamVisitor* pVisitor = GetManaged(nKey);
		if(pVisitor == NULL)
		{
			pVisitor = new ModelParamVisitor;
			ASSERT(pVisitor);
			pVisitor->SetWindowParam(m_pParentWnd, m_rect, m_bVisible);
			Add(nKey, pVisitor);
		}
		return pVisitor;
	}

	void SetVisitorParam(CWnd* pParentWnd, const CRect& rect, BOOL bIsVisible){
		m_pParentWnd = pParentWnd;
		m_rect = rect;
		m_bVisible = bIsVisible;
	}
private:
	CWnd* m_pParentWnd;
	CRect m_rect;
	BOOL m_bVisible;
};

#define WM_PARTAVIALABLE WM_USER+2

class DllExport CDlgSupport : public CDialog
{
// Construction
public:
	CDlgSupport(BOOL IsCancel = TRUE, CWnd* pParent = NULL);   // standard constructor

	DECLARE_DYNCREATE(CDlgSupport);
// Dialog Data
	//{{AFX_DATA(CDlgSupport)
	enum { IDD = IDD_SUPPORT };
	CTreeCtrl	m_SupportTree;
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDlgSupport)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

public:
	void DeletePart(Part* pPart);
	enum MASK{
	eSUPPORT,
	eSTRING,
	ePART,
	eATTACH
	};
	void AddSupport(SupportHanger* pSupport);
	void AddJoint(Joint* pJoint, HTREEITEM Parent = TVI_ROOT);
	void GetPropertyViewRect(CRect& Rect);
	void AddPart(Part* pPart);
	ModelParamVisitorManager& ModelVisitorManager(){
		return m_theModelVisitorManager;
	}

private:
	void AddSupportToTree(SupportHanger* pSupport);
	HTREEITEM AddObjectToTree(ModelObject* pObject, INT ObjectStyle, INT nVisitorKey, HTREEITEM hParent = TVI_ROOT);

private:
	CArray<SupportHanger*, SupportHanger*> m_theSupports;
	CArray<Joint*, Joint*> m_theJoints;
	CArray<Part*, Part*> m_theParts;
	ModelParamVisitorManager m_theModelVisitorManager;
	BOOL m_bIsCancel;

public:
	
	class DllExport TreeObject{
	public:
		TreeObject(CTreeCtrl* pTree, CDlgSupport* pParent = NULL);
		~TreeObject();

	public:
		BOOL SetParam(HTREEITEM handle, CWnd* pWnd, BOOL bIsVisible);
		VOID AddTreeObject (TreeObject* pObject);
		BOOL DeleteObject(void* pPointer);
		TreeObject* FindTreeObject(HTREEITEM handle);

	public:
		HTREEITEM m_handle;
		void* m_pPointer;
		INT m_mask;
		CTreeCtrl* m_pTree;
		CDlgSupport* m_pParent;

	public:
		
		CArray<TreeObject* ,TreeObject*> m_TreeObject;
	};

	VOID SetParam(HTREEITEM handle, BOOL bIsVisible);
	
	TreeObject m_Tree;
// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CDlgSupport)
	virtual BOOL OnInitDialog();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSelchangedSupportTree(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnDestroy();
	afx_msg LRESULT OnUpdateListCtrl(WPARAM nState, LPARAM pPoint);
	virtual void OnOK();
	afx_msg LRESULT OnPartAvialable(WPARAM wParam, LPARAM lParam);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLGSUPPORT_H__BE7BBB1E_38A3_4B11_A990_73A4719CD3DA__INCLUDED_)
